package com.vf.admin.miaodong.controller;

import com.vf.admin.client.service.*;
import com.vf.admin.common.BaseController;
import com.vf.admin.common.Constants;
import com.vf.admin.common.entity.Result;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.*;
import com.vf.admin.miaodong.service.AfterFollowService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 关注记录管理
 */
@Controller
@RequestMapping("/after/follow")
public class AfterFollowController extends BaseController{
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    AfterFollowService afterFollowService;

    /**
     * 关注接口
     * @param userId 关注人Id
     * @param beiguanzhuId 被关注人Id
     * @return
     */
    @RequestMapping("/guanzhu")
    public Result guanzhu(Integer userId, Integer beiguanzhuId){
        String guanzhu = afterFollowService.guanzhu(userId, beiguanzhuId);
        return this.sucessJSON(guanzhu);
    }


    /**
     * 关注记录列表
     * @param splitPageBean
     * @param startDate  开始时间
     * @param endDate  结束时间
     * @param bgznick  被关注人名称
     * @param bgzphone  被关注人手机号
     * @param followednick  关注人的昵称
     * @param followedphone  关注人的手机号
     * @param status 关注状态 1关注  2取消关注
     * @return
     */
    @RequestMapping("/list")
    public String list(SplitPageBean splitPageBean,String startDate,String endDate,String bgznick,
                       String bgzphone,String followednick,String followedphone,Integer status){
        try{
            Map<String,Object> map = new HashMap<>();
            map.put("startDate",startDate);
            map.put("endDate",endDate);
            map.put("bgznick",bgznick);
            map.put("bgzphone",bgzphone);
            map.put("followednick",followednick);
            map.put("followedphone",followedphone);
            map.put("status",status);
            List<AppFollow> list = afterFollowService.list(map,splitPageBean);
            //关注状态
            Map<Integer,String> statusMap = Constants.getGzztMap();
            request.setAttribute("statusMap",statusMap);
            request.setAttribute("list",list);
            request.setAttribute("splitPage",splitPageBean);
            request.setAttribute("startDate",startDate);
            request.setAttribute("endDate",endDate);
            request.setAttribute("bgznick",bgznick);
            request.setAttribute("bgzphone",bgzphone);
            request.setAttribute("followednick",followednick);
            request.setAttribute("followedphone",followedphone);
            request.setAttribute("status",status);
            return this.sucess("/web/after/follow/list");
        }catch (Exception e){
            logger.error("查看关注记录列表异常",e);
            return this.error("系统繁忙");
        }
    }
}
